﻿/// <reference path="../jquery/jquery-1.3.2-vsdoc.js" />
/// <reference path="Complaint.Namespaces.js" />
/// <reference path="Complaint.Common.js" />

var URL = Complaint.Common.SiteRoot + "/Complaint/AddComment/" + complaintId;
var reportURL = Complaint.Common.SiteRoot + "/Complaint/ReportComment";

$(function() {
    $("#dialog").dialog({
        autoOpen: false,
        bgiframe: true,
        modal: true,
        width: 400,
        buttons:
                {
                    "Cancel": function() {
                        $(this).dialog("close");
                    },
                    "OK": function() {
                        // post back to add comment
                        var formData = $("div.form input,div.form textarea").serialize();
                        var obj = {
                            type: "POST",
                            dataType: "html",
                            timeout: 30000,
                            url: URL,
                            data: formData,
                            error: errorhandler,
                            success: function(data) {
                                $("div#commentsContainer").html(data);
                                $("#dialog").dialog("close");
                            }
                        };
                        $.ajax(obj);
                    }
                }
    });

    $("#addComment").click(function(evt) {
        $.get(
                    URL,
                    {},
                    function(data) {
                        $("#dialog").html(data);
                        $("#dialog").dialog("open");
                    }
                );
    });

    $("table#tblComments td p a")
        .live("click", function(evt) {
            evt.preventDefault();
            $.post(
            reportURL,
            { id: $(this).attr("id") },
            function(data) {
                alert(data);
            });
        });

    var initialRating = $('#satisfaction-literal').text();
    $('#satisfaction')
            .ratings({ stars: 5, initialRating: initialRating, readOnly: 1 });

    $('#satisfaction-literal').text(Complaint.Common.SatisfactionLevel[initialRating - 1]);
});

var errorhandler = function(XMLHttpRequest, textStatus, errorThrown) {
    $("#dialog").html(XMLHttpRequest.responseText);
};